package leecode

func pivotIndex(nums []int) int {
	prefix := make([]int, len(nums)+1)
	for i := 0; i < len(nums); i++ {
		prefix[i+1] = prefix[i] + nums[i]
	}
	for i := 1; i < len(prefix); i++ {
		if prefix[i-1] == prefix[len(prefix)-1]-prefix[i] {
			return i - 1
		}
	}
	return -1
}
